<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>

	<body>
		<div id="box">
			<button type="button" onclick="fn1()">高考倒计时</button>
			<button type="button" onclick="fn2()">停止</button>
			
		</div>
		<script type="text/javascript">
			//1.10天后是几月几号;
			(function() {
				var a1 = new Date(); //获取当前日期
				console.log(a1);
				var a2 = a1.getTime(); //获取当前日期的时间戳
				var a3 = a2 + 10 * 24 * 3600 * 1000; //当前日期的时间戳 + 后边10天的毫秒数 = 十天之后到1970的时间戳
				var a4 = new Date(a3); //获取十天之后的日期
				var y = a4.getFullYear(); //获取十天之后的年份
				var m = a4.getMonth() + 1; //获取十天之后的月份
				var d = a4.getDate(); //获取十天之后的日期
				console.log("十天之后是", y, '年', m, '月', d, '日');
			})()

			//2.加入今天是2019年2月25日,10天后几月几号;
			;
			(function() {
				var n1 = new Date(2019, 2, 25);
				var n2 = n1.getTime();
				var n3 = n2 + 10 * 24 * 3600 * 1000;
				var n4 = new Date(n3);
				var n5 = n4.getFullYear();
				var n6 = n4.getMonth();
				var n7 = n4.getDate();
				console.log("10天之后", n5, '年', n6, '月', n7, '日');
			}());

			//3.2020年是7月7日,请问,现在距离高考还有几天?
			(function() {
				var d1 = new Date();
				var d2 = new Date(2020, 7, 7);
				var d3 = d1.getTime();
				var d4 = d2.getTime();
				//				var d5 = d4 - d3;
				var d5 = d2 - d1;
				console.log(d5);
				//				var d6 = .getHours();
				//				console.log(d6);
			})()

			;
			(function() {
				var d1 = new Date();
				//var d2=new Date(2020,06,13,0,0,0);
				var d2 = new Date("2020-07-07")
				var t1 = d1.getTime();
				var t2 = d2.getTime();
				var t3 = (t2 - t1) / 1000;
				//1s=1000ms;
				console.log("t3:", t3);
				//1min=60s;1h=60min=3600s;1day=24h=24*60min=24*3600s=86400s;
				var n1 = parseInt(t3 / 86400);
				console.log("剩余的天数", n1);

				//})();
			}());

			//4.设计距离2020年7月7日,高考倒计时格式如下
			//  距离2020年高考,还有X天X小时X分钟X秒
			//fn1();
             var t100;
			function fn1() {
				 t100=setInterval(function() {
					var d1 = new Date();
					//var d2=new Date(2020,06,13,0,0,0);
					var d2 = new Date("2020-07-07")
					var t1 = d1.getTime();
					var t2 = d2.getTime();
					var t3 = (t2 - t1) / 1000;
					//1s=1000ms;
					//					console.log("t3:", t3);
					//1min=60s;1h=60min=3600s;1day=24h=24*60min=24*3600s=86400s;
					var n1 = parseInt(t3 / 86400);
					//					console.log("剩余的天数", n1);
					var n2 = t3 % 86400;
					//					console.log("剩余不够一天秒数", n2);
					var h = parseInt(n2 / 3600);
					//					console.log("还剩的小时数",h);
					var n3 = n2 % 3600;
					//					console.log("不够一小时的秒数",n3);
					var min = parseInt(n3 / 60);
					//console.log("剩余的分钟数",min);
					var s = parseInt(n3 % 60);
					//console.log("还剩下的秒数",s);
					console.log("距离2020年高考，还有", n1, "天", h, "小时", min, "分钟", s, "秒");
				}, 1000)
			}
			function fn2(){
				clearInterval(t100);
			}
		</script>
	</body>

</html>